package com.lcxw.hxzbapi.controller.membercontroller;

import com.lcxw.hxzbapi.entity.pojo.Photo;
import com.lcxw.hxzbapi.entity.requestBean.PhotoDelReq;
import com.lcxw.hxzbapi.entity.requestBean.PhotoUploadReq;
import com.lcxw.hxzbapi.entity.requestBean.RequestParamBasic;
import com.lcxw.hxzbapi.entity.response.Response;
import com.lcxw.hxzbapi.service.PhotoService;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/user/photo")
public class PhotoController {

    @Resource
    PhotoService photoService;

    @Resource
    MemberRealization memberRealization;

    /**
     * 上传相册图片接口
     */
    @PostMapping("/upload")
    public Response uploadPhoto(@RequestBody @Validated PhotoUploadReq requestBody) {

        return memberRealization.uploadPhoto(requestBody);

    }

    /**
     * 删除一张相册图片接口
     */
    @PostMapping("/delete")
    public Response deletePhoto(@RequestBody @Validated PhotoDelReq requestBody) {

        return memberRealization.deletePhoto(requestBody);

    }

    /**
     * 获取所有相册图片接口
     */
    @PostMapping("/getAll")
    public Response getAllPhoto(@RequestBody RequestParamBasic requestBody) {

        long userId = Long.parseLong(requestBody.getUserId());

        List<Photo> photos = photoService.selectByUserId(userId);

        return Response.ok(photos);

    }

}
